package com.ynet.middleground.riskmanage.service.impl.qichacha;

import com.google.common.base.Throwables;
import com.ynet.core.common.ServiceResult;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.bean.qichacha.operationstate.ADSTLicenseDetailReq;
import com.ynet.middleground.riskmanage.bean.qichacha.operationstate.ADSTLicenseListReq;
import com.ynet.middleground.riskmanage.bean.qichacha.operationstate.TaxCreditReq;
import com.ynet.middleground.riskmanage.dto.qichacha.operationstate.ADSTLicenseDetailDTO;
import com.ynet.middleground.riskmanage.dto.qichacha.operationstate.ADSTLicenseListDTO;
import com.ynet.middleground.riskmanage.dto.qichacha.operationstate.TaxCreditDTO;
import com.ynet.middleground.riskmanage.service.impl.GenericService;
import com.ynet.middleground.riskmanage.model.qichacha.OperationStateModel;
import com.ynet.middleground.riskmanage.service.qichacha.OperationStateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;

/**
 * @ClassName OperationStateServiceImpl
 * @Description 企查查经营状况接口实现类
 * @Author zhangyongbin
 * @Date 2020/8/10 16:01
 * @Version 1.0
 */
@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Consumes({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Api(value = "企查查经营状况接口服务", tags = {"企查查经营状况接口服务"})
@Path("qcc")
@Service(timeout = 6000, version = "0.0.1")
public class OperationStateServiceImpl implements OperationStateService, GenericService {

    @Autowired
    OperationStateModel operationStateModel;

    @POST
    @ApiOperation(value = "行政许可核查,每页条数最大不超过20", notes = "行政许可核查,每页条数最大不超过20")
    @ApiImplicitParam(name = "requestObj", dataType = "ADSTLicenseListReq", paramType = "body", required = true)
    @Path("licenceList")
    @Override
    public ServiceResult<List<ADSTLicenseListDTO>>
        getAdministrativeLicenseList(@Valid ADSTLicenseListReq aDSTLicenseListReq) {
        ServiceResult<List<ADSTLicenseListDTO>> result = new ServiceResult<>();

        try {
            result.setResult(operationStateModel.getAdministrativeLicenseList(aDSTLicenseListReq));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "行政许可核查服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        result.setPagerInfo(aDSTLicenseListReq.getPagerInfo());
        return result;

    }

    @POST
    @ApiOperation(value = "行政许可详情（信用中国）", notes = "行政许可详情（信用中国）")
    @ApiImplicitParam(name = "requestObj", dataType = "ADSTLicenseDetailReq", paramType = "body", required = true)
    @Path("licenceDetail")
    @Override
    public ServiceResult<ADSTLicenseDetailDTO>
        getAdministrativeLicenseDetail(@Valid ADSTLicenseDetailReq aDSTLicenseDetailReq) {
        ServiceResult<ADSTLicenseDetailDTO> result = new ServiceResult<>();

        try {
            result.setResult(operationStateModel.getAdministrativeLicenseDetail(aDSTLicenseDetailReq));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "行政许可详情（信用中国）服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }

    @POST
    @ApiOperation(value = "税务信用列表", notes = "税务信用列表")
    @ApiImplicitParam(name = "requestObj", dataType = "TaxCreditReq", paramType = "body", required = true)
    @Path("taxcredit")
    @Override
    public ServiceResult<List<TaxCreditDTO>> getTaxCreditList(@Valid TaxCreditReq taxCreditReq) {
        ServiceResult<List<TaxCreditDTO>> result = new ServiceResult<>();

        try {
            result.setResult(operationStateModel.getTaxCreditList(taxCreditReq));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "税务信用列表服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }
}
